(function () {


    /* -------------- loading页面的隐藏 --------------*/
    var loading = document.getElementsByClassName('loading')[0];
    
    setTimeout(function(){
        loading.style.opacity = 0;
        setTimeout(function(){
            loading.style.display = 'none';
        },2000);
    },4000);


    /* 点击内容标签的切换 */
    var aArr = document.getElementsByTagName('a');

    //阻止a标签的默认跳转
    for (var i = 0, len = aArr.length; i < len; i++) {
        //可同时绑定click和tap事件  在手机端和pc端都可以进行事件

        aArr[i].onclick = function(e){
            e.preventDefault();
            active(this.parentNode);
        };

        (function(i){
            tap(aArr[i], active, aArr[i].parentNode);
        })(i);
    }


    /* -----------------  fun ------------------- */
    function active(that) {
        var lis = that.parentNode.children,
            ulWidth = that.parentNode.offsetWidth;

        for (var i = 0, len = lis.length; i < len; i++) {
            //所有宽度变为 10%
            animateS(lis[i], {
                width: ulWidth * .1
            });
        }
        animateS(that, {
            //当前宽度变为 60%
            width: ulWidth * .6
        });
    }


    /**
     * 
     * @param {*} dom         ------------     要绑定tap事件的dom元素
     * @param {*} callback    ------------     要执行的回调
     * @param {*} arguments   ------------     把callback中传入的参数在后续进行传参
     */
    function tap(dom, callback) {
        var time = 0,
            flag = false,
            //接收传入的参数
            args = [].slice.call(arguments, 2);
            
        dom.addEventListener('touchstart', function(){
            time = Date.now();
        });
        dom.addEventListener('touchmove', function(){
            flag = true;
        });
        dom.addEventListener('touchend', function(){
            time = Date.now() - time;
            if(!flag && time<200) {
                //利用apply进行传参
                callback && callback.apply(dom, args);
            }
        });
    }

})();